package com.itmuch.cloud.study.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.itmuch.cloud.study.entity.MaterialQrCode;
import com.itmuch.cloud.study.service.ItemBarService;

import io.swagger.annotations.ApiOperation;

@RestController
public class ItemBarController {

	@Autowired
	private ItemBarService itemBarService;
	
	private static int limitNum = 5000;
	
	@ApiOperation(value="通过restful调用创建物料信息", notes="根据url传递的参数，持久化相关信息")
	@PostMapping("/bindrelation")
	@Transactional
	public String saveItemBar(@RequestBody MaterialQrCode code){
		String message = "{\"msg\": \"数据不能为空\",\"success\": false}";
		
		if (code != null) {
			if(code.getItemCode()!= null && code.getBarCodes() != null){
				if(code.getBarCodes().size()<=limitNum){
					message = itemBarService.saveItemBar(code.getItemCode(),code.getBarCodes());
				}else{
					message = "{\"msg\": \"数据一次不能超过"+limitNum+"\",\"success\": false}";
				}
			}else{
				return message;
			}
		}else{
			return message;
		}
		return message;
		
	} 
}
